package com.example.hydropowermanage.mapper;

import com.example.hydropowermanage.pojo.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("insert into message(sender, receiver, content, status, send_time) values (#{sender}, #{receiver}, #{content}, #{status}, #{send_time})")
    @Options(useGeneratedKeys = true, keyProperty = "msgId")
    void insertMessage(Message message);

    @Select("select * from message where receiver = #{receiver}")
    List<Message> getUserMessages(String receiver);

    @Select("select * from message where msgid = #{id}")
    Message getMessageById(Long id);

    @Update("update message set status = #{status} where msgid = #{id}")
    void updateMessageStatus(@Param("id") Long id, @Param("status") String status);

    @Delete("delete from message where msgid = #{id}")
    void deleteMessage(Long id);

    @Select("select * from message")
    List<Message> getAllMessages();

}
